package com.sxt;

import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.sxt.copy.Jsoup1;
import com.sxt.copy.Jsoup2;
import com.sxt.entity.Article;
import com.sxt.service.ArticleService;

public class sina {
	private final static String BiUrl = "https://www.aicoin.cn/news/all";
	private static String biUrl = "http://www.bishijie.com/shendu_";
	public static List<String> getUrl() throws IOException{
		Document doc = Jsoup.connect(BiUrl).get();
		Elements els = doc.select("div.container");
		List<String> list = new ArrayList<String>();
		for (Element element : els) {
			String pageView = element.select("span.pageView").text();
			int count = Integer.parseInt(pageView);
			if(count>1000){
			String href = element.select("div.container").attr("id");
			  list.add(biUrl+href);
			}
		}
		return list;
	}
    public static void add(String url){
    	 List<String> list = Jsoup1.addArticle(url, 
					"div.second-title", 
					"div#artibody");
 	//启动Spring容器
		ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
		ArticleService articleService=(ArticleService) context.getBean("articleService");
		Article art =new Article();
		
		String id =String.valueOf((int) (Math.random()*1000000000));
       art.setId(id);
       art.setTitle(list.get(0));
       art.setTags("Dapp");
       art.setAuthorId("1535422958143");
       art.setContent(list.get(1));
       art.setCommentCount(0);
   	  art.setViewCount(0);
       art.setRewardContent("");
   	  art.setRewardPoint(0);
       art.setPermalink("/article/"+art.getId());
       Long l = System.currentTimeMillis();
        String date = l.toString();
   	  art.setCreateTime(new BigInteger(date));
       art.setUpdateTime(new BigInteger(date));
   	  art.setLatestCmtTime(new BigInteger("0"));
       art.setLatestCmterName("");
       art.setRandomDouble(Math.random());
       art.setCommentable("1");
       
       art.setEditorType(0);
       art.setArticleStatus(0);
   	  art.setArticleType(0);
       art.setGoodCnt(0);
   	  art.setBadCnt(0);
       art.setCollectCnt(0);
       art.setWatchCnt(0);
       art.setRedditScore(0d);
       art.setCity("");
       art.setIP("127.0.0.1");
       art.setUA("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0");
       art.setStick(new BigInteger("0"));
       art.setAnonymous(0);
       art.setPerfect(0);
       art.setAnonymousView(0);
       art.setAudioURL("");
       art.setQnAOfferPoint(0);
       art.setPushOrder(0);
		articleService.register(art);
    	
    	
    }
    
	public static void main(String[] args) throws Exception{
		List<String> urls = new ArrayList<String>();
		 
		 urls.add("http://finance.sina.com.cn/blockchain/roll/2018-07-26/doc-ihfvkitw8133073.shtml");
		 urls.add("http://finance.sina.com.cn/chanjing/cyxw/2018-06-07/doc-ihcscwwz7643715.shtml");
		 urls.add("http://tech.sina.com.cn/roll/2018-03-10/doc-ifyscmut8685519.shtml");
		 urls.add("http://finance.sina.com.cn/blockchain/coin/2018-07-16/doc-ihfkffak4773501.shtml");
		 urls.add("http://finance.sina.com.cn/blockchain/coin/2018-08-19/doc-ihhxaafy6301032.shtml");
		 urls.add("http://finance.sina.com.cn/blockchain/coin/2018-08-02/doc-ihhehtqf4796828.shtml");
		 urls.add("http://finance.sina.com.cn/roll/2018-03-04/doc-ifyrzinh2941892.shtml");
		 
		
		 
		 
		

		 
		
		 
		 
		 for (String url : urls) {
			 add(url);
		}
     
     }
}
